/**
 * Created by zeopean on 2015/9/16.
 */

jQuery(function(){
    /** 初始化ajax */
    jQuery.ajaxSetup({
        case:false,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    /** 管理员用户登录操作 */
    $('.btn').bind('click' , function(){
        var username = $('input[name=username]').val();
        var password = $('input[name=password]').val();
        var remember = $('input[name=remember]').is(':checked');

        if(username=='' || password=='') {
            noty({text: '您的账号或者密码不能为空！', type: 'error', timeout: 800});
            return false;
        }

        $.ajax({
            type:"post",
            url:SignIn,
            dataType:"json",
            data:{
                "username":username ,
                "password":password,
                "remember":remember
            },
            success:function(obj){
                if(obj.level === "success"){
                    window.location.href=Home;
                }else{
                    noty({text:obj.message,type:obj.level,timeout:800});
                }
            },
            error:function(obj){
                var datajson = obj.responseJSON;
                noty({text:datajson.message,type:datajson.level,timeout:800});
            }
        });
    });


});